﻿using Framework.MVC.Infrastructure;
using Framework.Infrastructure;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Framework.Domain.Enum;

namespace Framework.MVC.Controllers
{
    public class CommonController : BaseController
    {
        /// <summary>
        /// 接口操作码自动生成，方便前端查看
        /// </summary>
        /// <param name="type">错误码类型 0或System：系统错误码、1或WeiXin：微信错误码、2或WeiBo：微博错误码</param>
        /// <returns></returns>
        public ContentResult GetReturnCode(ReturnCodeType type = ReturnCodeType.System)
        {
            Dictionary<string, Dictionary<int, string>> dic;
            StringBuilder sbStr = new StringBuilder();
            switch (type)
            {
                default:
                case ReturnCodeType.System:
                    sbStr.Append("<!DOCTYPE html><html><head><title>系统错误码</title></head><body>");
                    dic = Common.GetEnumDescriptions(typeof(ReturnCode_System));
                    break;
                case ReturnCodeType.WeiXin:
                    sbStr.Append("<!DOCTYPE html><html><head><title>微信错误码</title></head><body>");
                    dic = Common.GetEnumDescriptions(typeof(ReturnCode_WeiXin));
                    break;
                case ReturnCodeType.WeiBo:
                    sbStr.Append("<!DOCTYPE html><html><head><title>微博错误码</title></head><body>");
                    dic = Common.GetEnumDescriptions(typeof(ReturnCode_WeiBo));
                    break;
            }
            foreach (var item in dic.Keys)
            {
                sbStr.Append("<div style='font-weight:bold'>" + item + "</div>");
                foreach (var content in dic[item])
                {
                    sbStr.Append("<div>" + content.Key + "：" + content.Value + "</div>");
                }
                sbStr.Append("<br />");
            }
            sbStr.Append("</body></html>");
            return Content(sbStr.ToString());
        }

        /// <summary>
        /// 404页面
        /// </summary>
        public JsonResult Error404()
        {
            return Json(new ReturnModel_Common { success = false, code = ReturnCode_System.找不到页面, msg = "404_PAGE_NOT_FOUND" });
        }


    }
}